package com.aidong.jobs.async;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import com.cloopen.rest.sdk.CCPRestSDK;

@Service("smsTask")
public class SmsTask {
	private static CCPRestSDK restAPI = new CCPRestSDK();
	private static final String captchaTemplateId = "110395";
	private static final String activeRemindTemplateId = "110412";
	private static final String ptTemplateId = "110411";
	private static final String storeTemplateId = "110410";
	private static final String foodTemplateId = "110401";
	private static final String transportTemplateId = "110408";
	private static final String courseRemindTemplateId = "110397";
	private static final String courseAppointTemplateId = "110414";
	private static final String campaignRemindTemplateId = "110421";
	static {
		restAPI.init("app.cloopen.com", "8883");
		// 初始化服务器地址和端口，生产环境配置成app.cloopen.com，端口是8883.
		restAPI.setAccount("8a216da85697f5420156a193bc880813", "c687d5ac5cec4557b381c068dd4ed48a");
		// 初始化主账号名称和主账号令牌，登陆云通讯网站后，可在"控制台-应用"中看到开发者主账号ACCOUNT SID和
		restAPI.setAppId("8a216da85697f5420156a1a549b0084e");
	}

	@Async
	public void captcha(String cellNumber, String captcha) {
		restAPI.sendTemplateSMS(cellNumber, captchaTemplateId, new String[] { captcha });
	}

	@Async
	public void activityRemind(String cellNumber, String title, String subscribeId, String date, String address,
			String voucherNo, String phone) {
		restAPI.sendTemplateSMS(cellNumber, activeRemindTemplateId,
				new String[] { title, date, address, phone, "，验证码：" + voucherNo });
	}

	@Async
	public void ptAppointment(String cellNumber, String ptChName, String ptEnName, String date, String address,
			int subscribeId) {
		restAPI.sendTemplateSMS(cellNumber, ptTemplateId,
				new String[] { String.valueOf(subscribeId), ptChName + "（" + ptEnName + "）", date, address });
	}

	@Async
	public void storeAppointment(String cellNumber, String storeName, String date, String address, String subscribeId) {
		restAPI.sendTemplateSMS(cellNumber, storeTemplateId, new String[] { storeName, subscribeId, date, address });
	}

	@Async
	public void foodAppointment(String cellNumber, String quantity, String foodName, String pickDate, String storeName,
			String voucherNo, String phone) {
		restAPI.sendTemplateSMS(cellNumber, foodTemplateId,
				new String[] { quantity + "份" + foodName, pickDate, storeName, phone + "，验证码：" + voucherNo });
	}

	@Async
	public void courseAppointment(String cellNumber, String subscribeId, String courseName, String date,
			String storeName, String voucherNo, String phone) {
		restAPI.sendTemplateSMS(cellNumber, courseAppointTemplateId,
				new String[] { courseName, subscribeId + "", date, storeName, phone + "，验证码：" + voucherNo });

	}

	@Async
	public void foodAppointmentT(String cellNumber, String quantity, String foodName) {
		restAPI.sendTemplateSMS(cellNumber, transportTemplateId, new String[] { quantity + "份" + foodName });
	}

	@Async
	public void courseRemind(String cellNumber, String courseName, String courseDate, String storeName, String time) {
		restAPI.sendTemplateSMS(cellNumber, courseRemindTemplateId,
				new String[] { courseName, time, courseDate, storeName });
	}

	@Async
	public void campaignRemind(String cellNumber, String CampaignTitle, String courseDate, String placeName,
			String time) {
		restAPI.sendTemplateSMS(cellNumber, campaignRemindTemplateId,
				new String[] { CampaignTitle, time+"分钟", courseDate, placeName });

	}

}
